package cn.jimmie.lib.qlog;

import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Func :
 *
 * <p> Create Time:  2019-12-18 11:00 </p>
 * <p> @author Jimmie.Qian  </p>
 */
public enum QFormat {
    DEFAULT {
        @Override
        public String format(String source) {
            return source;
        }
    },
    JSON {
        @Override
        public String format(String source) {
            if (TextUtils.isEmpty(source)) return source;
            try {
                source = source.trim();
                if (source.startsWith("{") && source.endsWith("}")) {
                    return new JSONObject(source).toString(4);
                } else if (source.startsWith("[") && source.endsWith("]")) {
                    return new JSONArray(source).toString(4);
                }
            } catch (Throwable ignore) {
            }
            return source;
        }
    };

    public abstract String format(String source);
}
